package com.hebang.stcommunityapp.repostory;

import android.content.Context;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hebang.stcommunityapp.NetClient;
import com.hebang.stcommunityapp.NetUrlStr;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class Repostory {
    private static Repostory instance = new Repostory();
    private Repostory(){
    }
    public static Repostory getInstance(){
        return instance;
    }

    /**
     * 请求登录
     * @param context
     * @param param
     * @param LoginEvent
     */
    public  void  doLogin(final Context context, String param,final MutableLiveData<Boolean> LoginEvent){
        if(!NetUrlStr.isTest){
            LoginEvent.setValue(true);
        }else{
            NetClient.getInstance(context).postAsynWithJson(NetUrlStr.LOGIN, param,null, new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {
                    LoginEvent.postValue(false);
                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    try {
                        LoginEvent.postValue(true);
                    }catch (Exception e){
                        LoginEvent.postValue(false);
                    }

                }
            });
        }
    }


}
